package com.cmcc.cmii.smsmail.listener;

import com.alibaba.fastjson.JSONObject;
import com.cmcc.cmii.common.utils.JsonUtil;
import com.cmcc.cmii.smsmail.constants.MailMqConstants;
import com.cmcc.cmii.smsmail.dto.ExcepMsgDto;
import com.cmcc.cmii.smsmail.service.IMailSendFailService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Thanks
 * 监听发送失败的邮件  进行入库及重试等操作
 */
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Slf4j
public class MailSendFailListener {

    private final IMailSendFailService iMailSendFailService;


    /**
     * 处理发送失败
     * @param jsonStr
     */
    @RabbitListener(bindings = @QueueBinding(value = @Queue(value = MailMqConstants.MAIL_SEND_FAIL_QUEUE, durable = "true"),
            exchange = @Exchange(value = MailMqConstants.MAIL_SEND_FAIL_EXCHANGE,
                    ignoreDeclarationExceptions = "true",
                    type = ExchangeTypes.TOPIC, durable = "true"), key = MailMqConstants.MAIL_SEND_FAIL_KEY))
    public void handle(String jsonStr){
        ExcepMsgDto excepMsgDto=(ExcepMsgDto)JsonUtil.getModelFromJson(jsonStr, ExcepMsgDto.class);

    }
}
